<%@ page import="sell.DbTest" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: webrx
  Date: 2017/6/9
  Time: 19:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加大分类</title>
</head>
<style>
    .fu02{
        margin: 20px auto;
        width: 80%;
        height: 50%;
    }
    .fu02 th,td{
        border:1px solid #b1ff20;
        text-align: center;
    }
</style>
<body>
<%
    DbTest mu = new DbTest();
    request.setCharacterEncoding("utf-8");

    if(request.getMethod().equals("POST")&&request.getParameter("id")!=null){
        String ss=request.getParameter("id");
        int nn =Integer.parseInt(ss);
        mu.insert("insert into fuzhang values(null,?,?,?) ",new Object[]{request.getParameter("name1"),nn,request.getParameter("path")+request.getParameter("id")+","});
    }else if(request.getMethod().equals("POST")&&request.getParameter("name2")!=null){
        mu.insert("insert into fuzhang values(null,?,?,?)",new Object[]{request.getParameter("name2"),0,"0,"});
    }
    try {
        if(request.getParameter("delete").equals("delete")){
            mu.delete("fuzhang","where id="+request.getParameter("did"));
        }
    }catch (Exception e){

    }



    List<Map<String,Object>> list = mu.query("fuzhang","*","","order by concat(path,id)","");

%>
<hr>
<form action="sell_fuzhuangadd.jsp" method="post">
    <%
        String id= request.getParameter("id");
        String info ="根分类";
        if(id!=null){
            info =request.getParameter("name")+"的子类";
        }
        request.setAttribute("info",info);
    %>
    ${info}
    <%
        if(id!=null) {
    %>
    :<input type="text" name="name1" >&nbsp;
    <input type="text" name="path" hidden value="${param.path}">
     <input type="text" name="id" hidden value="${param.id}" >
    <%
        }else {
    %>
    :<input type="text" name="name2" >&nbsp;
    <%
        }
    %>
    <input type="submit" value="添加">
</form>
<hr>
<hr>
<table class="fu02" cellpadding="0" cellspacing="0">
    <tr>
        <th>ID</th>
        <th>类名</th>
        <th>根分类</th>
        <th>根分类路径</th>
        <th>基本操作</th>
    </tr>
    <%
        for(Map<String, Object> m :list){
    %>
    <tr>
        <td><%=m.get("id")%></td>
        <td><%=m.get("fu_name")%></td>
        <td><%=m.get("pid")%></td>
        <td><%=m.get("path")%></td>
        <td>
            <a href="?id=<%=m.get("id")%>&path=<%=m.get("path")%>&name=<%=m.get("fu_name")%>">添加子分类</a>&nbsp;&nbsp;
            <a href="?did=<%=m.get("id")%>&delete=<%="delete"%>">删除</a>
        </td>
    </tr>
    <%
        }
    %>
    <tr>
        <td colspan="10">
            <a href="sell_fuzhuangadd.jsp">添加根分类</a></td>
    </tr>
</table>
</body>
</html>
